var lng, lat, uid , ws,member_id,share_k;
var f_id = 0;
var app = angular.module("App", []);
	app.controller('circleController', function($scope, $http) {
		$scope.initView = function($uid){
			plus.nativeUI.showWaiting('加载中...');
			$http.get(circle + "/index.php?act=theme&op=theme&c_id=1&member_id="+$uid)
			.success(function(response) {
				plus.nativeUI.closeWaiting();
//				console.log(circle + "/index.php?act=group&op=mobile_index&c_id=1&lng="+$lng+"&lat="+$lat+"&uid="+$uid);
				console.log(JSON.stringify(response));
				if(response.length > 0){
					$scope.circles = response;
				}else{ 
					toast('暂无更多数据...');
				}
				
//				$scope.affix = response.affix_list; 
//				$scope.info = response.group_info;
				$(".friends_post").on('click', function() {
					uid = plus.storage.getItem('id');
					if(!uid) {    
						mui.toast("请登录..."); 
						openNewPage("login.html");
					}   
					//@流星 这个地方应该增加动画效果  
					console.log(response.group_info.circle_id); 
					plus.webview.create("Friends_post.html","Friends_post.html",{},{
						c_id:response.group_info.circle_id,spage:ws.id
					}).show('slide-in-right',500);
				})
 
				 
				
			})
		} 
		$scope.theme_onlike = function(t_id,c_id,theme_nolikes,k){
//			console.log(t_id+'--'+c_id+'--'+theme_nolikes+'--'+k+'--'+uid); 
			if(theme_nolikes == 0) { //1可以赞  0不可以 
				likeNo($('.like'+k), { t_id: t_id, c_id: c_id, u_id: uid });
			} else {    
				if(!uid) {  
					console.log(member_id);
					mui.toast("请先登录");
					openNewPage("login.html");
				} else {
					likeYes($('.like'+k), { t_id: t_id, c_id: c_id, u_id: uid });
				}

			}
		}
		$scope.theme_Friends = function(t_id,c_id){
			gotoreply(c_id,t_id,0);
		}
		$scope.share_friend = function(t_id,c_id,keys){
				$(".alert-back").toggle();
		        $(".alert").slideToggle();
		        tid = t_id;
		        cid = c_id;
		        share_k = keys;
		}
		$scope.gray_friend = function(t_id,c_id,keys){
//			console.log(keys);return; 
			plus.nativeUI.confirm( "该帖子删除后将不可查看，您确定要删除这个帖子吗?", function(e){
				if(e.index==0){
					plus.nativeUI.showWaiting('正在删除...');
					$.ajax({
						type:"get",
						url:circle + "/index.php?act=theme&op=share_upd",
						data:{
							t_id:t_id,
							c_id:c_id,
							u_id:member_id
						},
						success:function(data){
							
							console.log(JSON.stringify(data));
							if(data > 0){
								plus.nativeUI.closeWaiting();
								toast('删除成功！');
								$('.friend'+keys).remove();
							}else{
								plus.nativeUI.closeWaiting();
								toast('删除失败！');
							}
						},
						error:function(e){
						 	plus.nativeUI.closeWaiting();
						}
					});
				}
			}, "校伙伴", ["是","否"] );


			
		}
		
	})
document.addEventListener('plusready', function() {
	  aboutElement = document.querySelector('[ng-controller=circleController]');
	  $scope = angular.element(aboutElement).scope();
	  ws = plus.webview.currentWebview();
	  uid = plus.storage.getItem('id');
	  $scope.initView(uid);
	  $scope.$apply(); 
})


function gotoDetail(obj) { 
//	console.log($(obj).attr('c_id'));return;
	plus.nativeUI.showWaiting("加载中...");
	detail = plus.webview.create("Friends_details.html", "Friends_details.html", {}, {
		t_id: $(obj).attr('t_id'),c_id: $(obj).attr('c_id')
	});
	detail.addEventListener('loaded', function() {
		plus.nativeUI.closeWaiting();
		detail.show('slide-in-right', 300, null, {
			acceleration: 'auto'
		});
	});
}